<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import="com.broadvision.web.util.ViewDynaBean" %>
<%@ page import="org.apache.commons.beanutils.PropertyUtils" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld"  prefix="bean"   %>
<%@ taglib uri="/WEB-INF/struts-html.tld"  prefix="html"   %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"  %>

<script language="JavaScript">

//
// Trims leading blanks.
//
function stringLeftTrim(s) {
  return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s) {
  return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s) {
  return stringRightTrim(stringLeftTrim(s));
}

//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}


function searchUserPopup(popupUrl, parentFormName, parentFieldName) {
  var thisForm = document.forms[parentFormName];
  var windowName = parentFormName + parentFieldName;
  var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
  var urlDummy="<%=request.getContextPath()%>"+"/mt/user/userPopupHelper.jsp?parentFormName="+parentFormName+"&parentFieldName="+parentFieldName;
  var popupWindow=window.open(urlDummy,windowName,windowFeatures);
  if ( popupWindow != null) {
    if( popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

//
// 'callback' function to the parentWindow to set the selected fieldValue
//
function setFieldValue(refreshUrl, formName, fieldName, fieldValue) {

  var thisForm = document.forms[formName];
  var elements = thisForm.elements;
  var numElements = elements.length;

  var field;

  for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
    var elementName = elements[elementIndex].name;
    if (elementName == fieldName) {
      field = elements[elementIndex];
      break;
    }
  }

  if (field.type == 'text') {
    field.value = fieldValue;
  }
  else if (field.type == 'hidden') {
    refreshParentWindow(refreshUrl, fieldName, fieldValue);
  }
}

function setFieldValueSimple(formName, fieldName, fieldValue) {

  var thisForm = document.forms[formName];
  var elements = thisForm.elements;
  var numElements = elements.length;

  var field;

  for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
    var elementName = elements[elementIndex].name;
    if (elementName == fieldName) {
      field = elements[elementIndex];
      break;
    }
  }

 field.value = fieldValue;

}


function refreshParentWindow(refreshUrl, fieldName, fieldValue)
{
  if (refreshUrl != null) {
    if (refreshUrl.indexOf("?") < 0) {
      refreshUrl += "?";
    } else {
      refreshUrl += "&";
    }
  }
  window.location = refreshURL + '.do' + fieldName + '=' + fieldValue;
}

function setUserAliasNew(formName, fieldValue, firstName, lastName,
fullName, userAlias) {
  // this page does not have any hidden fields that rely on the popup,
  // we do not need a refresh url.
  var refreshUrl = null;
  setUserFindFieldValue(refreshUrl, formName, fieldValue, firstName,
lastName, fullName, userAlias);
}
  
function setUserFindFieldValue(refreshUrl, formName, fieldValue,
firstName, lastName, fullName, userAlias) {

  var thisForm = document.forms[formName];
  var elements = thisForm.elements;
  var numElements = elements.length;

  if (fieldValue == "from") {
    if (thisForm.useFullName.value == "true") {
     thisForm.fullNameFrom.value = fullName;
    }
    else {
     thisForm.firstNameFrom.value = firstName;
     thisForm.lastNameFrom.value = lastName;
    }
    thisForm.userAliasFrom.value = userAlias;
  }
  else {
    if (thisForm.useFullName.value == "true") {
      thisForm.fullNameTo.value = fullName;
    }
    else {
      thisForm.firstNameTo.value = firstName;
      thisForm.lastNameTo.value = lastName;
    }
    thisForm.userAliasTo.value = userAlias;
  }
}

  function doPrev(myform) {
      myform.action = '<html:rewrite page="/bp/roleDelegateNew.do"/>';
      myform.submit();
      return true;
  }

  function isFormCancelOK(theForm) {
    //var ok = confirm('<bean:message key="confirmCancel"  bundle="bp.messages"/>');
    var ok = true;
    if (ok && theForm != null) {
      var fromSet = theForm.fromSet.value;
      if ("true" == fromSet) {
        theForm.action='<html:rewrite page="/bp/delegationList.do"/>';
      }
      else {
        theForm.action='<html:rewrite page="/bp/userSearch.do"/>';
      }
      theForm.submit();
    }
    return ok ;
  }

</script>

<% 
  java.util.HashMap map = new java.util.HashMap();

  map.put("userId", request.getParameter("userId"));
  map.put("timeFilter", request.getParameter("timeFilter"));
  map.put("fromSet", request.getParameter("fromSet"));
  map.put("formAction", request.getParameter("formAction"));
  map.put("delegationOid", request.getParameter("delegationOid"));
  map.put("delegatorId", request.getParameter("delegatorId"));
  map.put("delegateId", request.getParameter("delegateId"));
  map.put("type", request.getParameter("type"));

  map.put("start.month", request.getParameter("start.month"));
  map.put("start.day", request.getParameter("start.day"));
  map.put("start.year", request.getParameter("start.year"));
  map.put("end.month", request.getParameter("end.month"));
  map.put("end.day", request.getParameter("end.day"));
  map.put("end.year", request.getParameter("end.year"));

  map.put("description", request.getParameter("description"));
  map.put("endRadio", request.getParameter("endRadio"));
  map.put("firstHit", request.getParameter("firstHit"));

  map.put("firstNameFrom", request.getParameter("firstNameFrom"));
  map.put("lastNameFrom", request.getParameter("lastNameFrom"));
  map.put("fullNameFrom", request.getParameter("fullNameFrom"));
  map.put("userAliasFrom", request.getParameter("userAliasFrom"));

  map.put("firstNameTo", request.getParameter("firstNameTo"));
  map.put("lastNameTo", request.getParameter("lastNameTo"));
  map.put("fullNameTo", request.getParameter("fullNameTo"));
  map.put("userAliasTo", request.getParameter("userAliasTo"));

  String delegationOid = request.getParameter("delegationOid");
  if (null != delegationOid && !delegationOid.equals("-1")) {
    map.put("oldStart.month", request.getParameter("oldStart.month"));
    map.put("oldStart.day", request.getParameter("oldStart.day"));
    map.put("oldStart.year", request.getParameter("oldStart.year"));
    map.put("oldStart.hour", request.getParameter("oldStart.hour"));
    map.put("oldStart.minute", request.getParameter("oldStart.minute"));
    map.put("oldStart.ind", request.getParameter("oldStart.ind"));
    map.put("oldEnd.month", request.getParameter("oldEnd.month"));
    map.put("oldEnd.day", request.getParameter("oldEnd.day"));
    map.put("oldEnd.year", request.getParameter("oldEnd.year"));
    map.put("oldEnd.hour", request.getParameter("oldEnd.hour"));
    map.put("oldEnd.minute", request.getParameter("oldEnd.minute"));
    map.put("oldEnd.ind", request.getParameter("oldEnd.ind"));
  }

  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<!-- Zone 5 starts here.  -->

<html:form action="/bp/roleDelegateSelectUser.do">

<html:hidden property="useFullName"/>
<html:hidden property="formAction" value="save"/>
<html:hidden property="forwardAction"/>
<html:hidden property="fromSet"/>
<html:hidden property="firstHit" value="false"/>

<html:hidden property="userId" />
<html:hidden property="timeFilter" />
<html:hidden property="delegationOid" />
<html:hidden property="delegatorId" />
<html:hidden property="type" />

<logic:notEqual name="delegationEditForm" property="delegationOid" value="-1">
   <html:hidden property="oldStart.month" />
   <html:hidden property="oldStart.day" />
   <html:hidden property="oldStart.year" />
   <html:hidden property="oldStart.hour" />
   <html:hidden property="oldStart.minute" />
   <html:hidden property="oldStart.ind" />
   <html:hidden property="oldEnd.month" />
   <html:hidden property="oldEnd.day" />
   <html:hidden property="oldEnd.year" />
   <html:hidden property="oldEnd.hour" />
   <html:hidden property="oldEnd.minute" />
   <html:hidden property="oldEnd.ind" />
</logic:notEqual>

<html:hidden property="start.month" />
<html:hidden property="start.day" />
<html:hidden property="start.year" />
<html:hidden property="start.hour" />
<html:hidden property="start.minute" />
<html:hidden property="start.ind" />
<html:hidden property="end.month" />
<html:hidden property="end.day" />
<html:hidden property="end.year" />
<html:hidden property="end.hour" />
<html:hidden property="end.minute" />
<html:hidden property="end.ind" />
<html:hidden property="description" />
<html:hidden property="endRadio" />

<%
   ViewDynaBean delegationEditView = (ViewDynaBean) request.getAttribute("delegationEditView");
   String delegatorName = null;
   if (null != delegationEditView) {
     delegatorName = (String)
     PropertyUtils.getSimpleProperty(delegationEditView, "delegatorName");
   }
   StringBuffer pageTitle = new StringBuffer("bp.user.userDelegationEdit.pageTitle.processManager");
%>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.package.contentArea" bundle="bp.messages"/>">
  <tr>
    <td valign="top" width="100%">
		    
      <div class="pageTitle">
 	<logic:notEmpty name="delegationEditView" property="delegatorName">
          <bean:message key="<%=pageTitle.toString()%>" arg0="<%=delegatorName%>"  bundle="bp.messages"/>
        </logic:notEmpty>
	<logic:empty name="delegationEditView" property="delegatorName">
          <bean:message key="bp.user.delegation.processManagerRole" bundle="bp.messages"/>
        </logic:empty>
      </div>
			

      <!-- pageTab -->
      <div class="errorMessage">
        <logic:notEmpty name="delegationEditForm" property="errorMessage">
          <bean:write name="delegationEditForm" property="errorMessage"/>
        </logic:notEmpty>
        <logic:empty name="delegationEditForm" property="errorMessage">
          <html:errors bundle="bp.messages"/>
        </logic:empty>		
      </div>

      <%@include file="/mc/common/pagetab.jsp" %>
      <!-- end of PageTab -->			

      <div class="pageSubtitle">
          <span class="left"><bean:message key="bp.user.delegation.pageSubtitle.selectDelegate" bundle="bp.messages"/></span>
	<span class="right">&nbsp;</span>
      </div> 
		
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Search criterias">
        <tr> 
          <td class="label" width="10%" nowrap><bean:message key="bp.user.userDelegationListBody.header.from" bundle="bp.messages"/>:</td>
	  <logic:equal name="delegationEditForm" property="fromSet" value="true">
            <td class="labelField" width="10%" nowrap>
	      <bean:write name="delegationEditView" property="delegatorName"/>
            </td>
            <td class="labelField" width="10%" nowrap>&nbsp;</td>
            <td class="labelField" width="10%" nowrap>&nbsp;</td>
            <td class="labelField" width="60%" nowrap>&nbsp;</td>
          </logic:equal>

	  <logic:equal name="delegationEditForm" property="fromSet" value="false">
            <logic:equal name="delegationEditForm" property="useFullName" value="false">
              <td class="labelField" width="10%" nowrap>
	        <html:text name="delegationEditForm" property="firstNameFrom" size="20" maxlength="100" />
                <br><i>(<bean:message key="bp.user.label.firstName" bundle="bp.messages"/>)</i>
              </td>
              <td class="labelField" width="10%" nowrap>
	        <html:text name="delegationEditForm" property="lastNameFrom" size="20" maxlength="100" />
                <br><i>(<bean:message key="bp.user.label.lastName" bundle="bp.messages"/>)</i> 
              </td>
            </logic:equal>
          
            <logic:equal name="delegationEditForm" property="useFullName" value="true">
              <td class="labelField" width="20%" nowrap>
	        <html:text name="delegationEditForm" property="fullNameFrom" size="20" maxlength="50" />
                <br><i>(<bean:message key="bp.user.label.fullName" bundle="bp.messages"/>)</i>
              </td>
            </logic:equal>

            <td class="labelField" width="10%" nowrap>
	      <html:text name="delegationEditForm" property="userAliasFrom" size="20" maxlength="255" />
              <br><i>(<bean:message key="bp.user.label.loginId" bundle="bp.messages"/>)</i>
            </td>
            <td class="labelField" width="60%" nowrap>
              <input type="button" name="browse" class="pageButton"
                onClick="JavaScript:searchUserPopup('<html:rewrite page="/mt/userSearchPopup.do"/>', 'delegationEditForm','from');" value='<bean:message key="button.browse" bundle="bp.messages"/>'>

            </td>
          </logic:equal>
        </tr>
        <tr> 
          <td class="label" width="10%" nowrap><bean:message
key="bp.user.userDelegationListBody.header.to" bundle="bp.messages"/>:</td>

          <logic:equal name="delegationEditForm" property="useFullName" value="false">
            <td class="labelField" width="10%" nowrap>
	      <html:text name="delegationEditForm" property="firstNameTo" size="20" maxlength="100" />
              <br><i>(<bean:message key="bp.user.label.firstName" bundle="bp.messages"/>)</i>
            </td>
            <td class="labelField" width="10%" nowrap>
	      <html:text name="delegationEditForm" property="lastNameTo" size="20" maxlength="100" />
              <br><i>(<bean:message key="bp.user.label.lastName" bundle="bp.messages"/>)</i> 
            </td>
          </logic:equal>

          <logic:equal name="delegationEditForm" property="useFullName" value="true">
            <td class="labelField" width="10%" nowrap>
	      <html:text name="delegationEditForm" property="fullNameTo" size="20" maxlength="50" />
              <br><i>(<bean:message key="bp.user.label.fullName" bundle="bp.messages"/>)</i>
            </td>
          </logic:equal>

          <td class="labelField" width="10%" nowrap>
	    <html:text name="delegationEditForm" property="userAliasTo" size="20" maxlength="255" />
            <br><i>(<bean:message key="bp.user.label.loginId" bundle="bp.messages"/>)</i>
          </td>
          <td class="labelField" width="60%" nowrap>
              <input type="button" name="browse" class="pageButton"
                onClick="JavaScript:searchUserPopup('<html:rewrite page="/mt/userSearchPopup.do"/>', 'delegationEditForm','to');" value='<bean:message key="button.browse" bundle="bp.messages"/>'>

          </td>
        </tr>
      </table>
			  	
      <div class="pageButtonWrap" align="right">
        <html:button styleClass="inputButton" property="cancelBtn" onclick="bCancel=true; return isFormCancelOK(this.form)">
          <bean:message key="button.cancel" bundle="bp.messages"/>
        </html:button>
        &nbsp;&nbsp;
        <html:button property="prevBtn" styleClass="pageButton"
          onclick="javascript: return doPrev(this.form);">
          <bean:message key="button.previous"  bundle="bp.messages"/>
        </html:button>
        <html:submit  property="submitBtn" styleClass="pageButton" >
          <bean:message key="button.save" bundle="bp.messages"/>
        </html:submit>
      </div>
    </td>
  </tr>
</table>

</html:form>

<!--end zone 5 content here -->
